/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.dew.serviciosmultiples.util;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import static pe.edu.upc.dew.serviciosmultiples.util.Constants.FORMATER_YYYY_MM_DD;


/**
 *
 * @author bcano
 */
public class CalendarFormater {

    public static String obtenerFecha(){
        Calendar fechaActual = GregorianCalendar.getInstance();
        SimpleDateFormat formato = new SimpleDateFormat(FORMATER_YYYY_MM_DD);
        String fechaFormater = formato.format(fechaActual.getTime());

        return fechaFormater;
    }

    public static Date obtenerFechaCalendar(){
        Calendar fechaActual = GregorianCalendar.getInstance();

        return fechaActual.getTime();
    }

    public static Date convertirStringFecha(String cadena) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(FORMATER_YYYY_MM_DD);
            Date date = sdf.parse(cadena);
            return date;
        } catch (ParseException ex) {
            Logger.getLogger(CalendarFormater.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public static java.sql.Date convertirSqlDate(Date date) {
        java.sql.Date sqlDate = new java.sql.Date(date.getTime());

        return sqlDate;
    }

    public static java.sql.Date obtenerFechaActualSqlDate(){
        Calendar fechaActual = GregorianCalendar.getInstance();
        Date date = fechaActual.getTime();
        java.sql.Date sqlDate = new java.sql.Date(date.getTime());

        return sqlDate;
    }

   public static java.sql.Date convertirStringSqlDate(String cadena) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(FORMATER_YYYY_MM_DD);
            Date date = sdf.parse(cadena);
            java.sql.Date sqlDate = new java.sql.Date(date.getTime());
            System.out.print("fecha sqlDate: " +sqlDate);
            return sqlDate;
        } catch (ParseException ex) {
            Logger.getLogger(CalendarFormater.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
   }

}
